module.exports = options => {
    return async function errorHandler(ctx, next) {
        try {
            await next();
        } catch(e) {
            // ctx.app.emit('error', e, ctx);
            
            const { status = 500, message = '发生异常' } = e

            ctx.body = {
                code: status,
                message
            }
            ctx.status = status
        }
    };
};